package com.vecspace.web.servlet.model;

import java.lang.reflect.InvocationTargetException;

import com.vecspace.exception.HException;
import com.vecspace.utils.log.HLogger;

public class PageException {
	private boolean hasError = false;
	private String errorMessage;
	private String errorId;
	
	public PageException(String msg){
		hasError = true;
		errorMessage = msg;
	}
	public PageException(Exception e){
		Throwable throwable = null;
		if(e != null){
			throwable = e;
			if(e instanceof InvocationTargetException){
				InvocationTargetException invoEx = (InvocationTargetException)e;
				throwable = invoEx.getTargetException();
			}
			hasError = true;
			errorMessage = throwable.getMessage();
			if(errorMessage == null || errorMessage.length()==0){				 
				errorMessage = throwable.toString();
			}
			if(e instanceof HException){
				errorId = ((HException)e).getErrCode();
			}
			HLogger.DEFAULT().debug("Exception:"+ errorMessage);
		}
	}
	
	public boolean isHasError() {
		return hasError;
	}
	
	public void setHasError(boolean hasError) {
		this.hasError = hasError;
	}
	
	public String getErrorMessage() {
		return errorMessage;
	}
	
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	public String getErrorId() {
		return errorId;
	}
	public void setErrorId(String errorId) {
		this.errorId = errorId;
	}
	
	@Override
	public String toString(){
		return this.errorId + ":" + this.errorMessage;
	}
	
}
